home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 321 / compsrc3 / recog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  23.3 KB  |  915 lines

  1. /* Subroutines used by or related to instruction recognition.
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY.  No author or distributor
  8. accepts responsibility to anyone for the consequences of using it
  9. or for whether it serves any particular purpose or works at all,
  10. unless he says so in writing.  Refer to the GNU CC General Public
  11. License for full details.
  12.  
  13. Everyone is granted permission to copy, modify and redistribute
  14. GNU CC, but only under the conditions described in the
  15. GNU CC General Public License.   A copy of this license is
  16. supposed to have been given to you along with GNU CC so you
  17. can know your rights and responsibilities.  It should be in a
  18. file named COPYING.  Among other things, the copyright notice
  19. and this notice must be preserved on all copies.  */
  20.  
  21.  
  22. #include "config.h"
  23. #include "rtl.h"
  24. #include <stdio.h>
  25. #include "insn-config.h"
  26. #include "recog.h"
  27. #include "regs.h"
  28. #include "hard-reg-set.h"
  29.  
  30. static int inequality_comparisons_p ();
  31.  
  32. /* Nonzero means allow operands to be volatile.
  33.    This is 1 if you use recog_memoized, 0 if you don't.
  34.    init_recog and recog_memoized are responsible for setting it.
  35.    This way of handling it is not really clean and will be change later.  */
  36.  
  37. int volatile_ok;
  38.  
  39. rtx recog_addr_dummy;
  40.  
  41. /* On return from `constrain_operands', indicate which alternative
  42.    was satisfied.  */
  43.  
  44. int which_alternative;
  45.  
  46. /* Initialize data used by the function `recog'.
  47.    This must be called once in the compilation of a function
  48.    before any insn recognition may be done in the function.  */
  49.  
  50. void
  51. init_recog ()
  52. {
  53.   volatile_ok = 0;
  54.   recog_addr_dummy = gen_rtx (MEM, VOIDmode, 0);
  55. }
  56.  
  57. /* Try recognizing the instruction INSN,
  58.    and return the code number that results.
  59.    Remeber the code so that repeated calls do not
  60.    need to spend the time for actual rerecognition.
  61.  
  62.    This function is the normal interface to instruction recognition.
  63.    The automatically-generated function `recog' is normally called
  64.    through this one.  (The only exception is in combine.c.)  */
  65.  
  66. int
  67. recog_memoized (insn)
  68.      rtx insn;
  69. {
  70.   volatile_ok = 1;
  71.   if (INSN_CODE (insn) < 0)
  72.     INSN_CODE (insn) = recog (PATTERN (insn), insn);
  73.   return INSN_CODE (insn);
  74. }
  75.  
  76. /* Return 1 if the insn following INSN does not contain
  77.    any ordered tests applied to the condition codes.
  78.    EQ and NE tests do not count.  */
  79.  
  80. int
  81. next_insn_tests_no_inequality (insn)
  82.      rtx insn;
  83. {
  84.   register rtx next = NEXT_INSN (insn);
  85.  
  86.   return ((GET_CODE (next) == JUMP_INSN
  87.        || GET_CODE (next) == INSN
  88.        || GET_CODE (next) == CALL_INSN)
  89.       && ! inequality_comparisons_p (PATTERN (next)));
  90. }
  91.  
  92. static int
  93. inequality_comparisons_p (x)
  94.      rtx x;
  95. {
  96.   register char *fmt;
  97.   register int len, i;
  98.   register enum rtx_code code = GET_CODE (x);
  99.  
  100.   switch (code)
  101.     {
  102.     case REG:
  103.     case PC:
  104.     case CC0:
  105.     case CONST_INT:
  106.     case CONST_DOUBLE:
  107.     case CONST:
  108.     case LABEL_REF:
  109.     case SYMBOL_REF:
  110.       return 0;
  111.  
  112.     case LT:
  113.     case LTU:
  114.     case GT:
  115.     case GTU:
  116.     case LE:
  117.     case LEU:
  118.     case GE:
  119.     case GEU:
  120.       return (XEXP (x, 0) == cc0_rtx || XEXP (x, 1) == cc0_rtx);
  121.     }
  122.  
  123.   len = GET_RTX_LENGTH (code);
  124.   fmt = GET_RTX_FORMAT (code);
  125.  
  126.   for (i = 0; i < len; i++)
  127.     {
  128.       if (fmt[i] == 'e')
  129.     {
  130.       if (inequality_comparisons_p (XEXP (x, i)))
  131.         return 1;
  132.     }
  133.       else if (fmt[i] == 'E')
  134.     {
  135.       register int j;
  136.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  137.         if (inequality_comparisons_p (XVECEXP (x, i, j)))
  138.           return 1;
  139.     }
  140.     }
  141.         
  142.   return 0;
  143. }
  144.  
  145. /* Return 1 if OP is a valid general operand for machine mode MODE.
  146.    This is either a register reference, a memory reference,
  147.    or a constant.  In the case of a memory reference, the address
  148.    is checked for general validity for the target machine.
  149.  
  150.    Register and memory references must have mode MODE in order to be valid,
  151.    but some constants have no machine mode and are valid for any mode.
  152.  
  153.    If MODE is VOIDmode, OP is checked for validity for whatever mode
  154.    it has.
  155.  
  156.    The main use of this function is as a predicate in match_operand
  157.    expressions in the machine description.  */
  158.  
  159. int
  160. general_operand (op, mode)
  161.      register rtx op;
  162.      enum machine_mode mode;
  163. {
  164.   register enum rtx_code code = GET_CODE (op);
  165.   int mode_altering_drug = 0;
  166.  
  167.   if (mode == VOIDmode)
  168.     mode = GET_MODE (op);
  169.  
  170.   if (CONSTANT_P (op))
  171.     return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode)
  172.         && LEGITIMATE_CONSTANT_P (op));
  173.  
  174.   /* Except for certain constants with VOIDmode, already checked for,
  175.      OP's mode must match MODE if MODE specifies a mode.  */
  176.  
  177.   if (GET_MODE (op) != mode)
  178.     return 0;
  179.  
  180.   while (code == SUBREG)
  181.     {
  182.       op = SUBREG_REG (op);
  183.       code = GET_CODE (op);
  184.       mode_altering_drug = 1;
  185.     }
  186.   if (code == REG)
  187.     return 1;
  188.   if (code == CONST_DOUBLE)
  189.     return LEGITIMATE_CONSTANT_P (op);
  190.   if (code == MEM)
  191.     {
  192.       register rtx y = XEXP (op, 0);
  193.       if (! volatile_ok && op->volatil)
  194.     return 0;
  195.       GO_IF_LEGITIMATE_ADDRESS (mode, y, win);
  196.     }
  197.   return 0;
  198.  
  199.  win:
  200.   if (mode_altering_drug)
  201.     return ! mode_dependent_address_p (XEXP (op, 0));
  202.   return 1;
  203. }
  204.  
  205. /* Return 1 if OP is a valid memory address for a memory reference
  206.    of mode MODE.
  207.  
  208.    The main use of this function is as a predicate in match_operand
  209.    expressions in the machine description.  */
  210.  
  211. int
  212. address_operand (op, mode)
  213.      register rtx op;
  214.      enum machine_mode mode;
  215. {
  216.   return memory_address_p (mode, op);
  217. }
  218.  
  219. /* Return 1 if OP is a register reference of mode MODE.
  220.    If MODE is VOIDmode, accept a register in any mode.
  221.  
  222.    The main use of this function is as a predicate in match_operand
  223.    expressions in the machine description.  */
  224.  
  225. int
  226. register_operand (op, mode)
  227.      register rtx op;
  228.      enum machine_mode mode;
  229. {
  230.   if (GET_MODE (op) != mode && mode != VOIDmode)
  231.     return 0;
  232.  
  233.   while (GET_CODE (op) == SUBREG)
  234.     op = SUBREG_REG (op);
  235.  
  236.   return GET_CODE (op) == REG;
  237. }
  238.  
  239. /* Return 1 if OP is a valid immediate operand for mode MODE.
  240.  
  241.    The main use of this function is as a predicate in match_operand
  242.    expressions in the machine description.  */
  243.  
  244. int
  245. immediate_operand (op, mode)
  246.      register rtx op;
  247.      enum machine_mode mode;
  248. {
  249.   return ((CONSTANT_P (op)
  250.        || (GET_CODE (op) == CONST_DOUBLE
  251.            && (GET_MODE (op) == mode || mode == VOIDmode)))
  252.       && LEGITIMATE_CONSTANT_P (op));
  253. }
  254.  
  255. /* Return 1 if OP is a general operand that is not an immediate operand.  */
  256.  
  257. int
  258. nonimmediate_operand (op, mode)
  259.      register rtx op;
  260.      enum machine_mode mode;
  261. {
  262.   return (general_operand (op, mode)
  263.       && ! CONSTANT_P (op) && GET_CODE (op) != CONST_DOUBLE);
  264. }
  265.  
  266. /* Return 1 if OP is a register reference or immediate value of mode MODE.  */
  267.  
  268. int
  269. nonmemory_operand (op, mode)
  270.      register rtx op;
  271.      enum machine_mode mode;
  272. {
  273.   if (CONSTANT_P (op)
  274.       || (GET_CODE (op) == CONST_DOUBLE
  275.       && (GET_MODE (op) == mode || mode == VOIDmode)))
  276.     return LEGITIMATE_CONSTANT_P (op);
  277.  
  278.   if (GET_MODE (op) != mode && mode != VOIDmode)
  279.     return 0;
  280.  
  281.   while (GET_CODE (op) == SUBREG)
  282.     op = SUBREG_REG (op);
  283.  
  284.   return GET_CODE (op) == REG;
  285. }
  286.  
  287. /* Return 1 if OP is a valid operand that stands for pushing a
  288.    value of mode MODE onto the stack.
  289.  
  290.    The main use of this function is as a predicate in match_operand
  291.    expressions in the machine description.  */
  292.  
  293. int
  294. push_operand (op, mode)
  295.      rtx op;
  296.      enum machine_mode mode;
  297. {
  298.   if (GET_CODE (op) != MEM)
  299.     return 0;
  300.  
  301.   if (GET_MODE (op) != mode)
  302.     return 0;
  303.  
  304.   op = XEXP (op, 0);
  305.  
  306. #ifdef STACK_GROWS_DOWNWARD
  307.   if (GET_CODE (op) != PRE_DEC)
  308.     return 0;
  309. #else
  310.   if (GET_CODE (op) != PRE_INC)
  311.     return 0;
  312. #endif
  313.   return REGNO (XEXP (op, 0)) == STACK_POINTER_REGNUM;
  314. }
  315.  
  316. /* Return 1 if ADDR is a valid memory address for mode MODE.  */
  317.  
  318. int
  319. memory_address_p (mode, addr)
  320.      enum machine_mode mode;
  321.      register rtx addr;
  322. {
  323.   GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
  324.   return 0;
  325.  
  326.  win:
  327.   return 1;
  328. }
  329.  
  330. /* Return 1 if OP is a valid memory reference with mode MODE,
  331.    including a valid address.
  332.  
  333.    The main use of this function is as a predicate in match_operand
  334.    expressions in the machine description.  */
  335.  
  336. int
  337. memory_operand (op, mode)
  338.      register rtx op;
  339.      enum machine_mode mode;
  340. {
  341.   enum rtx_code code = GET_CODE (op);
  342.   int mode_altering_drug = 0;
  343.  
  344.   while (code == SUBREG)
  345.     {
  346.       op = SUBREG_REG (op);
  347.       code = GET_CODE (op);
  348.       mode_altering_drug = 1;
  349.     }
  350.  
  351.   return (GET_CODE (op) == MEM && general_operand (op, mode)
  352.       && ! (mode_altering_drug
  353.         && mode_dependent_address_p (XEXP (op, 0))));
  354. }
  355.  
  356. /* If BODY is an insn body that uses ASM_OPERANDS,
  357.    return the number of operands (both input and output) in the insn.
  358.    Otherwise return 0.  */
  359.  
  360. int
  361. asm_noperands (body)
  362.      rtx body;
  363. {
  364.   int noperands;
  365.  
  366.   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
  367.     /* Single output operand: BODY is (set OUTPUT (asm_operands ...)).  */
  368.     return XVECLEN (SET_SRC (body), 3) + 1;
  369.   else if (GET_CODE (body) == PARALLEL
  370.        && GET_CODE (XVECEXP (body, 0, 0)) == SET
  371.        && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
  372.     /* Multiple outputs: BODY is
  373.        (parallel [(set OUTPUT0 (asm_operands ...)) ...]).  */
  374.     return XVECLEN (SET_SRC (XVECEXP (body, 0, 0)), 3) + XVECLEN (body, 0);
  375.   else
  376.     return 0;
  377. }
  378.  
  379. /* Assuming BODY is an insn body that uses ASM_OPERANDS,
  380.    copy its operands (both input and output) into the vector OPERANDS,
  381.    the locations of the operands within the insn into the vector OPERAND_LOCS,
  382.    and the constraints for the operands into CONSTRAINTS.
  383.    Write the modes of the operands into MODES.
  384.    Return the assembler-template.
  385.  
  386.    If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
  387.    we don't store that info.  */
  388.  
  389. char *
  390. decode_asm_operands (body, operands, operand_locs, constraints, modes)
  391.      rtx body;
  392.      rtx *operands;
  393.      rtx **operand_locs;
  394.      char **constraints;
  395.      enum machine_mode *modes;
  396. {
  397.   register int i;
  398.   int noperands;
  399.   char *template;
  400.  
  401.   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
  402.     {
  403.       rtx asmop = SET_SRC (body);
  404.       /* Single output operand: BODY is (set OUTPUT (asm_operands ....)).  */
  405.  
  406.       noperands = XVECLEN (asmop, 3) + 1;
  407.  
  408.       /* The input operands are found in the 1st element vector.  */
  409.       /* Constraints for inputs are in the 2nd element vector.  */
  410.       for (i = 1; i < noperands; i++)
  411.     {
  412.       if (operand_locs)
  413.         operand_locs[i] = &XVECEXP (asmop, 3, i - 1);
  414.       if (operands)
  415.         operands[i] = XVECEXP (asmop, 3, i - 1);
  416.       if (constraints)
  417.         constraints[i] = XSTR (XVECEXP (asmop, 4, i - 1), 0);
  418.       if (modes)
  419.         modes[i] = GET_MODE (XVECEXP (asmop, 4, i - 1));
  420.     }
  421.  
  422.       /* The output is in the SET.
  423.      Its constraint is in the ASM_OPERANDS itself.  */
  424.       if (operands)
  425.     operands[0] = SET_DEST (body);
  426.       if (operand_locs)
  427.     operand_locs[0] = &SET_DEST (body);
  428.       if (constraints)
  429.     constraints[0] = XSTR (asmop, 1);
  430.       if (modes)
  431.     modes[0] = GET_MODE (SET_DEST (body));
  432.       template = XSTR (asmop, 0);
  433.     }
  434.   else
  435.     {
  436.       rtx asmop = SET_SRC (XVECEXP (body, 0, 0));
  437.       int nout = XVECLEN (body, 0);
  438.       int nin = XVECLEN (asmop, 3);
  439.  
  440.       noperands = XVECLEN (asmop, 3) + XVECLEN (body, 0);
  441.  
  442.       /* The input operands are found in the 1st element vector.  */
  443.       /* Constraints for inputs are in the 2nd element vector.  */
  444.       for (i = 0; i < nin; i++)
  445.     {
  446.       if (operand_locs)
  447.         operand_locs[i + nout] = &XVECEXP (asmop, 3, i);
  448.       if (operands)
  449.         operands[i + nout] = XVECEXP (asmop, 3, i);
  450.       if (constraints)
  451.         constraints[i + nout] = XSTR (XVECEXP (asmop, 4, i), 0);
  452.       if (modes)
  453.         modes[i + nout] = GET_MODE (XVECEXP (asmop, 4, i));
  454.     }
  455.       /* The outputs are in the SETs.
  456.      Their constraints are in the ASM_OPERANDS itself.  */
  457.       for (i = 0; i < nout; i++)
  458.     {
  459.       if (operands)
  460.         operands[i] = SET_DEST (XVECEXP (body, 0, i));
  461.       if (operand_locs)
  462.         operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
  463.       if (constraints)
  464.         constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
  465.       if (modes)
  466.         modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
  467.     }
  468.       template = XSTR (asmop, 0);
  469.     }
  470.  
  471.   return template;
  472. }
  473.  
  474. extern rtx plus_constant ();
  475. extern rtx copy_rtx ();
  476.  
  477. /* Given an rtx *P, if it is a sum containing an integer constant term,
  478.    return the location (type rtx *) of the pointer to that constant term.
  479.    Otherwise, return a null pointer.  */
  480.  
  481. static rtx *
  482. find_constant_term_loc (p)
  483.      rtx *p;
  484. {
  485.   register rtx *tem;
  486.   register enum rtx_code code = GET_CODE (*p);
  487.  
  488.   /* If *P IS such a constant term, P is its location.  */
  489.  
  490.   if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
  491.       || code == CONST)
  492.     return p;
  493.  
  494.   /* Otherwise, if not a sum, it has no constant term.  */
  495.  
  496.   if (GET_CODE (*p) != PLUS)
  497.     return 0;
  498.  
  499.   /* If one of the summands is constant, return its location.  */
  500.  
  501.   if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
  502.       && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
  503.     return p;
  504.  
  505.   /* Otherwise, check each summand for containing a constant term.  */
  506.  
  507.   if (XEXP (*p, 0) != 0)
  508.     {
  509.       tem = find_constant_term_loc (&XEXP (*p, 0));
  510.       if (tem != 0)
  511.     return tem;
  512.     }
  513.  
  514.   if (XEXP (*p, 1) != 0)
  515.     {
  516.       tem = find_constant_term_loc (&XEXP (*p, 1));
  517.       if (tem != 0)
  518.     return tem;
  519.     }
  520.  
  521.   return 0;
  522. }
  523.  
  524. /* Return 1 if OP is a memory reference
  525.    whose address contains no side effects
  526.    and remains valid after the addition
  527.    of a positive integer less than the
  528.    size of the object being referenced.
  529.  
  530.    We assume that the original address is valid and do not check it.  */
  531.  
  532. int
  533. offsetable_memref_p (op)
  534.      rtx op;
  535. {
  536.   return ((GET_CODE (op) == MEM)
  537.       && offsetable_address_p (GET_MODE (op), XEXP (op, 0)));
  538. }
  539.  
  540. /* Return 1 if Y is a memory address which contains no side effects
  541.    and would remain valid for mode MODE
  542.    after the addition of a positive integer less than the
  543.    size of that mode.
  544.  
  545.    We assume that the original address is valid and do not check it.  */
  546.  
  547. int
  548. offsetable_address_p (mode, y)
  549.      enum machine_mode mode;
  550.      register rtx y;
  551. {
  552.   register enum rtx_code ycode = GET_CODE (y);
  553.   register rtx z;
  554.   rtx y1 = y;
  555.   rtx *y2;
  556.  
  557.   if (CONSTANT_ADDRESS_P (y))
  558.     return 1;
  559.       
  560.   /* If the expression contains a constant term,
  561.      see if it remains valid when max possible offset is added.  */
  562.  
  563.   if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
  564.     {
  565.       int old = INTVAL (y1 = *y2);
  566.       int good;
  567.       INTVAL (y1) += GET_MODE_SIZE (mode) - 1;
  568.       good = memory_address_p (mode, y);
  569.       /* In any case, restore old contents of memory.  */
  570.       INTVAL (y1) = old;
  571.       return good;
  572.     }
  573.  
  574.   if (ycode == PRE_DEC || ycode == PRE_INC
  575.       || ycode == POST_DEC || ycode == POST_INC)
  576.     return 0;
  577.  
  578.   /* The offset added here is chosen as the maximum offset that
  579.      any instruction could need to add when operating on something
  580.      of the specified mode.  We assume that if Y and Y+c are
  581.      valid addresses then so is Y+d for all 0<d<c.  */
  582.  
  583.   z = plus_constant (y, GET_MODE_SIZE (mode) - 1);
  584.  
  585.   return memory_address_p (mode, z);
  586. }
  587.  
  588. /* Return 1 if ADDR is an address-expression whose effect depends
  589.    on the mode of the memory reference it is used in.
  590.  
  591.    Autoincrement addressing is a typical example of mode-dependence
  592.    because the amount of the increment depends on the mode.  */
  593.  
  594. int
  595. mode_dependent_address_p (addr)
  596.      rtx addr;
  597. {
  598.   GO_IF_MODE_DEPENDENT_ADDRESS (addr, win);
  599.   return 0;
  600.  win:
  601.   return 1;
  602. }
  603.  
  604. /* Return 1 if OP is a general operand
  605.    other than a memory ref with a mode dependent address.  */
  606.  
  607. int
  608. mode_independent_operand (mode, op)
  609.      rtx op;
  610. {
  611.   rtx addr;
  612.  
  613.   if (! general_operand (mode, op))
  614.     return 0;
  615.  
  616.   if (GET_CODE (op) != MEM)
  617.     return 1;
  618.  
  619.   addr = XEXP (op, 0);
  620.   GO_IF_MODE_DEPENDENT_ADDRESS (addr, lose);
  621.   return 1;
  622.  lose:
  623.   return 0;
  624. }
  625.  
  626. /* Given an operand OP that is a valid memory reference
  627.    which satisfies offsetable_memref_p,
  628.    return a new memory reference whose address has been adjusted by OFFSET.
  629.    OFFSET should be positive and less than the size of the object referenced.
  630. */
  631.  
  632. rtx
  633. adj_offsetable_operand (op, offset)
  634.      rtx op;
  635.      int offset;
  636. {
  637.   register enum rtx_code code = GET_CODE (op);
  638.  
  639.   if (code == MEM) 
  640.     {
  641.       register rtx y = XEXP (op, 0);
  642.  
  643.       if (CONSTANT_ADDRESS_P (y))
  644.     return gen_rtx (MEM, GET_MODE (op), plus_constant (y, offset));
  645.  
  646.       if (GET_CODE (y) == PLUS)
  647.     {
  648.       rtx z = y;
  649.       register rtx *const_loc;
  650.  
  651.       op = copy_rtx (op);
  652.       z = XEXP (op, 0);
  653.       const_loc = find_constant_term_loc (&z);
  654.       if (const_loc)
  655.         {
  656.           *const_loc = plus_constant (*const_loc, offset);
  657.           return op;
  658.         }
  659.     }
  660.  
  661.       return gen_rtx (MEM, GET_MODE (op), plus_constant (y, offset));
  662.     }
  663.   abort ();
  664. }
  665.  
  666. #ifdef REGISTER_CONSTRAINTS
  667.  
  668. /* Check the operands of an insn (found in recog_operands)
  669.    against the insn's operand constraints (found via INSN_CODE_NUM)
  670.    and return 1 if they are valid.
  671.  
  672.    WHICH_ALTERNATIVE is set to a number which indicates which
  673.    alternative of constraints was matched: 0 for the first alternative,
  674.    1 for the next, etc.
  675.  
  676.    In addition, when two operands are match
  677.    and it happens that the output operand is (reg) while the
  678.    input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
  679.    make the output operand look like the input.
  680.    This is because the output operand is the one the template will print.
  681.  
  682.    This is used in final, just before printing the assembler code.  */
  683.  
  684. struct funny_match
  685. {
  686.   int this, other;
  687. };
  688.  
  689. int
  690. constrain_operands (insn_code_num)
  691.      int insn_code_num;
  692. {
  693.   char *constraints[MAX_RECOG_OPERANDS];
  694.   register int c;
  695.   int noperands = insn_n_operands[insn_code_num];
  696.  
  697.   struct funny_match funny_match[MAX_RECOG_OPERANDS];
  698.   int funny_match_index;
  699.  
  700.   if (noperands == 0)
  701.     return 1;
  702.  
  703.   for (c = 0; c < noperands; c++)
  704.     constraints[c] = insn_operand_constraint[insn_code_num][c];
  705.  
  706.   which_alternative = 0;
  707.  
  708.   while (*constraints[0])
  709.     {
  710.       register int opno;
  711.       int lose = 0;
  712.       funny_match_index = 0;
  713.  
  714.       for (opno = 0; opno < noperands; opno++)
  715.     {
  716.       register rtx op = recog_operand[opno];
  717.       register char *p = constraints[opno];
  718.       int win = 0;
  719.       int val;
  720.  
  721.       /* `alter_subreg' should already have converted any SUBREG
  722.          that appears at the level of an operand.  */
  723.       while (GET_CODE (op) == SUBREG)
  724.         abort ();
  725.  
  726.       while (*p && (c = *p++) != ',')
  727.         switch (c)
  728.           {
  729.           case '=':
  730.           case '+':
  731.           case '?':
  732.           case '#':
  733.           case '!':
  734.           case '*':
  735.           case '%':
  736.         break;
  737.  
  738.           case '0':
  739.           case '1':
  740.           case '2':
  741.           case '3':
  742.           case '4':
  743.         /* This operand must be the same as a previous one.  */
  744.         /* This kind of constraint is used for instructions such
  745.            as add when they take only two operands.  */
  746.         /* Note that the lower-numbered operand is passed first.  */
  747.         val = operands_match_p (recog_operand[c - '0'],
  748.                     recog_operand[opno]);
  749.         if (val != 0)
  750.           win = 1;
  751.         /* If output is *x and input is *--x,
  752.            arrange later to change the output to *--x as well,
  753.            since the output op is the one that will be printed.  */
  754.         if (val == 2)
  755.           {
  756.             funny_match[funny_match_index].this = opno;
  757.             funny_match[funny_match_index++].other = c - '0';
  758.           }
  759.         break;
  760.  
  761.           case 'p':
  762.         /* p is used for address_operands, and everything
  763.            that must be checked was checked already.  */
  764.         win = 1;
  765.         break;
  766.  
  767.         /* No need to check general_operand again;
  768.            it was done in insn-recog.c.  */
  769.           case 'g':
  770.         /* Anything goes unless it is a REG and really has a hard reg
  771.            but the hard reg is not in the class GENERAL_REGS.  */
  772.         if (GENERAL_REGS == ALL_REGS
  773.             || GET_CODE (op) != REG
  774.             || (REGNO (op) >= FIRST_PSEUDO_REGISTER
  775.             && reg_renumber[REGNO (op)] < 0)
  776.             || reg_renumbered_fits_class_p (op, GENERAL_REGS, 0,
  777.                             GET_MODE (op)))
  778.           win = 1;
  779.         break;
  780.  
  781.           case 'r':
  782.         if (GET_CODE (op) == REG
  783.             && (GENERAL_REGS == ALL_REGS
  784.             || reg_renumbered_fits_class_p (op, GENERAL_REGS,
  785.                             0, GET_MODE (op))))
  786.           win = 1;
  787.         break;
  788.  
  789.           case 'm':
  790.         if (GET_CODE (op) == MEM)
  791.           win = 1;
  792.         break;
  793.  
  794.           case '<':
  795.         if (GET_CODE (op) == MEM
  796.             && (GET_CODE (XEXP (op, 0)) == PRE_DEC
  797.             || GET_CODE (XEXP (op, 0)) == POST_DEC))
  798.           win = 1;
  799.         break;
  800.  
  801.           case '>':
  802.         if (GET_CODE (op) == MEM
  803.             && (GET_CODE (XEXP (op, 0)) == PRE_INC
  804.             || GET_CODE (XEXP (op, 0)) == POST_INC))
  805.           win = 1;
  806.         break;
  807.  
  808.           case 'F':
  809.         if (GET_CODE (op) == CONST_DOUBLE)
  810.           win = 1;
  811.         break;
  812.  
  813.           case 'G':
  814.           case 'H':
  815.         if (GET_CODE (op) == CONST_DOUBLE
  816.             && CONST_DOUBLE_OK_FOR_LETTER_P (op, c))
  817.           win = 1;
  818.         break;
  819.  
  820.           case 's':
  821.         if (GET_CODE (op) == CONST_INT)
  822.           break;
  823.           case 'i':
  824.         if (CONSTANT_P (op))
  825.           win = 1;
  826.         break;
  827.  
  828.           case 'n':
  829.         if (GET_CODE (op) == CONST_INT)
  830.           win = 1;
  831.         break;
  832.  
  833.           case 'I':
  834.           case 'J':
  835.           case 'K':
  836.           case 'L':
  837.           case 'M':
  838.         if (GET_CODE (op) == CONST_INT
  839.             && CONST_OK_FOR_LETTER_P (INTVAL (op), c))
  840.           win = 1;
  841.         break;
  842.  
  843.           case 'o':
  844.         if (offsetable_memref_p (op))
  845.           win = 1;
  846.         break;
  847.  
  848.           default:
  849.         if (GET_CODE (op) == REG
  850.             && reg_renumbered_fits_class_p (op,
  851.                             REG_CLASS_FROM_LETTER (c),
  852.                             0, GET_MODE (op)))
  853.           win = 1;
  854.           }
  855.  
  856.       constraints[opno] = p;
  857.       /* If this operand did not win somehow,
  858.          this alternative loses.  */
  859.       if (! win)
  860.         lose = 1;
  861.     }
  862.       /* This alternative won; the operands are ok.
  863.      Change whichever operands this alternative says to change.  */
  864.       if (! lose)
  865.     {
  866.       while (--funny_match_index >= 0)
  867.         {
  868.           recog_operand[funny_match[funny_match_index].other]
  869.         = recog_operand[funny_match[funny_match_index].this];
  870.         }
  871.       return 1;
  872.     }
  873.  
  874.       which_alternative++;
  875.     }
  876.   return 0;
  877. }
  878.  
  879. /* Return 1 iff OPERAND (assumed to be a REG rtx)
  880.    is a hard reg in class CLASS when its regno is offsetted by OFFSET
  881.    and changed to mode MODE,
  882.    or is a pseudo reg allocated into such a hard reg.
  883.    If REG occupies multiple hard regs, all of them must by in CLASS.  */
  884.  
  885. int
  886. reg_renumbered_fits_class_p (operand, class, offset, mode)
  887.      rtx operand;
  888.      register enum reg_class class;
  889.      int offset;
  890.      enum machine_mode mode;
  891. {
  892.   if (GET_CODE (operand) == REG)
  893.     {
  894.       register int regno = REGNO (operand);
  895.       if (reg_renumber[regno] >= 0)
  896.     regno = reg_renumber[regno];
  897.       if (regno < FIRST_PSEUDO_REGISTER
  898.       && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
  899.                 regno + offset))
  900.     {
  901.       register int sr;
  902.       regno += offset;
  903.       for (sr = HARD_REGNO_NREGS (regno, mode) - 1;
  904.            sr > 0; sr--)
  905.         if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
  906.                      regno + sr))
  907.           break;
  908.       return sr == 0;
  909.     }
  910.     }
  911.   return 0;
  912. }
  913.  
  914. #endif /* REGISTER_CONSTRAINTS */
  915.